Skip to content

fix: [SDK-4901] skip ShortcutBadger on API 26+ to prevent SIGSEGV on Xiaomi devices - #2570

Merged
fadi-george merged 5 commits into
mainfrom
fix/shortcutbadger-sigsegv-api26
Jul 28, 2026
Merged

fix: [SDK-4901] skip ShortcutBadger on API 26+ to prevent SIGSEGV on Xiaomi devices#2570
fadi-george merged 5 commits into
mainfrom
fix/shortcutbadger-sigsegv-api26

Conversation

@fadi-george

@fadi-george fadi-george commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Description

One Line Summary

Skip ShortcutBadger badge updates on Android 8+ (API 26) to prevent native SIGSEGV crashes on Xiaomi devices.

Details

Motivation

ShortcutBadger causes a native SIGSEGV on certain Xiaomi devices (Redmi 10C, Redmi 9A) running Android 11-13. The crash occurs while updating the legacy launcher badge. Since SIGSEGV is a native crash, Java exception handling cannot intercept it.

Android 8+ handles app icon badges through notification channels and active notifications, so the legacy ShortcutBadger path is unnecessary on those versions.

Reported in OneSignal/react-native-onesignal#1766 and #2222. Tracked by SDK-4901.

Scope

On API 26+, skip both automatic and explicit ShortcutBadger updates. Pre-API 26 devices continue using ShortcutBadger unchanged.

Testing

Unit testing

Added BadgeCountUpdaterTests covering:

  • update() does not invoke ShortcutBadger on API 26.
  • updateCount() does not invoke ShortcutBadger on API 26.
  • updateCount() continues invoking ShortcutBadger before API 26.

Local validation:

  • Spotless
  • Detekt
  • Full debug unit-test suite
  • Minified GMS and Huawei release demo builds
  • Changed-line coverage: 100% (5/5 executable lines)

Manual testing

The affected Xiaomi hardware was not available locally. The regression tests prevent the crashing code path from being reached on the reported Android versions.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible
  • I have reviewed this PR myself, ensuring it meets each checklist item

@fadi-george
fadi-george changed the base branch from main to 5.7-main March 11, 2026 20:54
@fadi-george
fadi-george force-pushed the fix/shortcutbadger-sigsegv-api26 branch from 26c7e3a to 905aefb Compare March 11, 2026 21:00
@github-actions

github-actions Bot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

📊 Diff Coverage Report

Diff Coverage Report (Changed Lines Only)

Gate: aggregate coverage on changed executable lines must be ≥ 80% (JaCoCo line data for lines touched in the diff).

Changed Files Coverage

  • BadgeCountUpdater.kt: 5/6 touched executable lines (83.3%) (25 touched lines in diff)

Overall (aggregate gate)

5/6 touched executable lines covered (83.3% — requires ≥ 80%)

📥 View workflow run

@fadi-george
fadi-george force-pushed the fix/shortcutbadger-sigsegv-api26 branch from 905aefb to 5139ef3 Compare March 11, 2026 21:05
@fadi-george
fadi-george requested a review from nan-li March 12, 2026 18:36
@fadi-george fadi-george changed the title fix: skip ShortcutBadger on API 26+ to prevent SIGSEGV on Xiaomi devices fix: [SDK-4901] skip ShortcutBadger on API 26+ to prevent SIGSEGV on Xiaomi devices Jul 22, 2026
@fadi-george
fadi-george force-pushed the fix/shortcutbadger-sigsegv-api26 branch 2 times, most recently from 4a6177c to 3c784ce Compare July 22, 2026 18:34
@fadi-george
fadi-george changed the base branch from 5.7-main to main July 22, 2026 18:34
On Android 8+ (API 26), notification channels handle app icon badges
natively, making ShortcutBadger unnecessary. ShortcutBadger's
DefaultBadger fallback causes native SIGSEGV crashes on certain Xiaomi
devices (Redmi 10C, Redmi 9A) where MIUI's broadcast receiver has
buggy native code that cannot be caught at the Java level.

Fixes OneSignal/react-native-onesignal#1766

Made-with: Cursor
Co-authored-by: Cursor <cursoragent@cursor.com>
@fadi-george
fadi-george force-pushed the fix/shortcutbadger-sigsegv-api26 branch from 3c784ce to f251cfd Compare July 28, 2026 03:19
@fadi-george

Copy link
Copy Markdown
Contributor Author

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — straightforward, well-tested fix.

Extended reasoning...

Overview

This PR changes BadgeCountUpdater.update() and updateCount() to skip ShortcutBadger entirely on API 26+ (Android O and above), guarding against a native SIGSEGV crash observed on some Xiaomi devices. The refactor introduces a private constructor with an injected _sdkInt field (defaulting to Build.VERSION.SDK_INT via a public secondary constructor) plus a @VisibleForTesting factory method, enabling the new unit tests to exercise both old and new SDK-version branches deterministically. Only two files are touched: the production class and its new test file.

Security risks

None. This is a defensive change to skip a legacy compatibility library on newer API levels; it does not touch auth, crypto, network, or data handling.

Level of scrutiny

Low-to-moderate is appropriate here. The change is small, localized to a single class, does not alter the public API surface (the primary constructor is now private but a compatible public secondary constructor preserves external construction), and existing callers construct BadgeCountUpdater through the DI module using the public constructor, which is unaffected. The bug-hunting pass found no issues, and I independently confirmed no other callers rely on the old primary constructor.

Other factors

Test coverage is solid: new unit tests explicitly cover the O-and-above skip path for both update() and updateCount(), and confirm the pre-O and pre-M paths still invoke ShortcutBadger as before. Diff coverage is 80% (4/5 changed executable lines), just meeting the CI gate. The three candidate lint/detekt concerns raised by the finder agents (missing @ChecksSdkIntAtLeast, @RequiresApi lint recognition, detekt baseline) are Kotlin-file style/tooling nitpicks that don't affect runtime correctness and were correctly ruled out.

@fadi-george
fadi-george merged commit 63b5057 into main Jul 28, 2026
6 checks passed
@fadi-george
fadi-george deleted the fix/shortcutbadger-sigsegv-api26 branch July 28, 2026 17:14
fadi-george added a commit that referenced this pull request Jul 30, 2026
…Xiaomi devices (#2570)

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants